<% layout('/layout/default.html', {title: '用户管理', libs: ['layout','zTree']}){ %>
<div class="ui-layout-west">
    <div class="main-content">
        <div class="ui-layout-header">
            <i class="fa icon-grid"></i> 组织机构
            <div class="header-tools float-right">
                <button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i
                        class="fa fa-chevron-up"></i></button>
                <button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i
                        class="fa fa-chevron-down"></i></button>
                <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新"><i class="fa fa-refresh"></i>
                </button>
            </div>
        </div>
        <div class="ui-layout-content">
            <div id="tree" class="ztree"></div>
        </div>
    </div>
</div>
<div class="ui-layout-center">
    <iframe id="subFrame" name="subFrame" class="iframe" src="${ctx}/sys/user/list"></iframe>
</div>
<% } %>
<script>
    // 初始化布局
    $('body').layout({west__size: 180}, 'body');
    // 主页框架
    var win = $("#subFrame")[0].contentWindow;
    // 树结构初始化加载
    var setting = {
        view: {selectedMulti: false}, data: {key: {title: "title"}, simpleData: {enable: true}},
        callback: {
            onClick: function (event, treeId, treeNode) {
                tree.expandNode(treeNode);
                console.log(treeNode);
                win.$('input[type=reset]').click();
                win.$("input[type='hidden']").val("");
                win.$('#officeId').val(treeNode.id);
                win.$('#officeName').val(treeNode.name);
                win.page();
            }
        }
    }, tree, loadTree = function () {
        js.ajaxRequest("${ctx}/sys/office/treeData", {ctrlPermi: '2'/*1拥有的权限 2管理的权限*/}, function (data) {
            tree = $.fn.zTree.init($("#tree"), setting, data);//.expandAll(true);
            // 展开第一级节点
            var nodes = tree.getNodesByParam("level", 0);
            for (var i = 0; i < nodes.length; i++) {
                tree.expandNode(nodes[i], true, false, false);
            }
            // 展开第二级节点
// 		nodes = tree.getNodesByParam("level", 1);
// 		for(var i=0; i<nodes.length; i++) {
// 			tree.expandNode(nodes[i], true, false, false);
// 		}
        });
    };
    loadTree();
    // 工具栏按钮绑定
    $('#btnExpand').click(function () {
        tree.expandAll(true);
        $(this).hide();
        $('#btnCollapse').show();
    });
    $('#btnCollapse').click(function () {
        tree.expandAll(false);
        $(this).hide();
        $('#btnExpand').show();
    });
    $('#btnRefresh').click(function () {
        loadTree();
    });
</script>
